# -*- coding: utf-8 -*-
import scrapy


class TaobaoSpider(scrapy.Spider):
    name = 'taobao'
    allowed_domains = ['cntv.cn']
    start_urls = ['http://tv.cntv.cn/videoset/C10586/page/6']

    def parse(self, response):
        content = response.xpath('//*[@id="sample_time_content_1"]/div[1]/ul/li')

        for o in content:
            temp = {}
            temp['o_title'] = o.xpath('./h3/a/text()').get()
            temp['url'] = o.xpath('./h3/a/@href').get()
            # print(o_title)
            # yield scrapy.Request(temp['url'], callback=self.tiqu, meta={temp: temp})
            yield temp

        url_cont = response.xpath('//*[@id="sample_time_content_1"]/div[3]/a[11]/@href').get()
        print(url_cont)
        nuxt_url = response.urljoin(url_cont)

        yield scrapy.Request(nuxt_url, callback=self.parse)

    # def tiqu(self, response):
    #     temp = response.meta['temp']
    #     temp['content'] = response.xpath('//*[@id="jieshao"]/div[2]/div/p[5]/a/text()').get()
    #     yield temp
